<?php $this->headScript()->appendFile($this->js('plugins/jquery.bt.min.js'))?>
<script>
$(document).ready(function(){
	 $("#classes, #student_numbers").bt({
         trigger: ['focus', 'blur'],
         positions: ['right']
       });
     $("#appendGroupBtn").click(function(){
    	 $("#group_sn").attr('value','');
    	 $("#setForm").show();
      });

     // 刪除
     $(".deleteBtn").click(function(){
         if (confirm('<?php echo $this->translate("Are you sure delete it ?")?>')) {
    	    var id = $(this).attr('id').substr(2);
    	    var currTr = $(this).parents('tr');
    	    $.getJSON('<?php echo $this->route("delete-group")?>',{sn:id},function(data){
    	        if (data) {
    	        	currTr.remove();
    	        	$("#setForm").hide();
    	        }
        	 });
         }
      });

     // 修改
     $(".editBtn").click(function(){
    	    var id=$(this).attr('id').substr(2);
    	    $.getJSON('<?php echo  $this->route("get-group-data")?>',{sn:id},function(data){
    	        $("#group_name").attr('value',data.group_name);
    	        $("#is_exclusive-"+data.is_exclusive).attr('checked','checked');
    	        $("#student_numbers").attr('value',data.student_numbers);
    	        $("#classes").attr('value',data.classes);
    	        $("#group_sn").attr('value',data.group_sn);
    	        $("#setForm").show();
        	 });

      });

     $(".editBtn , .deleteBtn").hover(
    	     function(){
        	     $(this).addClass('hoveBtn')
        	   },
        	  function(){
             	  $(this).removeClass('hoveBtn')
            }
       );

     $("#goHomeBtn").click(function(){
         window.location='<?php echo  $this->route("index")?>';
     });

     <?php if ($this->form->isErrors()):?>
     $("#setForm").show();
     <?php endif?>
});
</script>

<style>
.listTable {background:#9ebcdd; width:75%; margin: 5px auto;}
.listTable td {padding:3px;background:#fff; }
.listTable th {padding:3px;font-weight: bold; text-align:center;}
.editBtn , .deleteBtn{ color:blue; border:#ccc solid thin; padding:1px 3px; cursor: pointer;}
.hoveBtn {background:#ff5 }
</style>
<div style="overflow:auto; hekgth:300px">
<table class="listTable">
<thead>
<tr><th colspan=5 style="background: #fff"><?php echo  $this->translate('rand title')?>-- 2.學生群組設定
<input type="button" id="appendGroupBtn" value="<?php echo  $this->translate('append group')?>" />
<input type="button" id="goHomeBtn" value="<?php echo  $this->translate('return home page')?>" />
</th></tr>
<tr>
<th><?php echo  $this->translate('group_name')?></th>
<th><?php echo  $this->translate('is_exclusive')?></th>
<th><?php echo  $this->translate('student_numbers')?></th>
<th><?php echo  $this->translate('classes')?></th>
<th><?php echo  $this->translate('act')?></th>
</tr>
</thead>
<tbody>
<?php foreach($this->allData as $val):?>
<tr style="text-align:center">
<td><?php echo  $val['group_name']?></td>
<td><?php echo  ($val['is_exclusive'])?$this->translate('yes'):$this->translate('no')?></td>
<td><?php echo  $val['student_numbers']?></td>
<td><?php echo  ($val['classes'])?$val['classes']: '-'?></td>
<td>
<span id="e-<?php echo  $val['group_sn']?>" class="editBtn">
<?php echo  $this->translate('edit')?></span>
<span id="s-<?php echo  $val['group_sn']?>" class="deleteBtn">
<?php echo  $this->translate('delete')?></span>
</td>
</tr>
<?php endforeach?>
</tbody>
</table>
</div>

<table class="listTable" id="setForm" style="display:none" >
<tbody>
<tr>
<td>
<?php echo  $this->form?>
</td>
</tr>
</tbody>
</table>